<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
    <title>代理商管理系统</title>
    <link rel="stylesheet" type="text/css" href="${ctx}/statics/easyui/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="${ctx}/statics/easyui/themes/icon.css" />
    <link rel="stylesheet" type="text/css" href="${ctx}/statics/easyui/themes/color.css" />
    <link rel="stylesheet" type="text/css" href="${ctx}/statics/easyui/themes/demo.css" />
    <script src="${ctx}/statics/easyui/jquery.min.js" type="text/javascript"></script>
    <script src="${ctx}/statics/easyui/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="${ctx}/statics/easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
</head>
<body class="easyui-layout" >
    <form method="post" id="add" >
        <div data-options="region:'north',split:false" style="height:150px;background:#eee;padding:10px 20px 10px 20px">
            <div style="padding-left:10px;margin-bottom:10px"><h5 style="margin:0">基本信息</h5></div>
            <div style="border:1px solid lightgrey;padding-left:10px">
                <p>
                    <span style="width:60px;text-align:justify;display:inline-block">
                        企业名称:
                    </span>
                    <input id="customName" class="easyui-textbox" type="text" name="customName" style="width:150px;"
                            data-options="required:true,missingMessage:'必填'" />
                    <span id="customNameError" error style="width:150px;color:red;display:inline-block"></span>
                    <span style="margin-left:50px;width:60px;text-align:justify;display:inline-block">企业类型:</span>
                    <input name="customType" value="--请选择--" style="width:150px" />
                    <input type="hidden" name="customTypeName" value="" />
                </p>
                <p style="margin-top:20px">
                    <span style="width:60px;text-align:justify;display:inline-block">
                        企业主页:
                    </span>
                    <input class="easyui-textbox" type="text" name="siteUrl" style="width:150px;"
                            data-options="required:true,missingMessage:'必填'" />
                    <span id="siteUrlError" error style="width:150px;color:red;display:inline-block"></span>
                    <span style="margin-left:50px;width:60px;text-align:justify;display:inline-block">
                        状态:
                    </span>
                    <select class="easyui-combobox" name="customStatus" style="width:150px;">
                        <option value='true' selected >启用</option>
                        <option value='false' >不启用</option>
                    </select>
                </p>
            </div>
        </div>
        <div data-options="region:'south',split:false" style="height:130px;background:#eee;padding:10px">
            <p style="text-align:center;margin-top:70px">
                <a href="javascript:void(0)" class="easyui-linkbutton c6"
                   onclick="submitForm()" style="width:60px;margin-right:10px;">保存</a>
                <a href="javascript:void(0)" class="easyui-linkbutton c6"
                   onclick="cancel()" style="width:60px;">返回</a>
            </p>
        </div>
        <div data-options="region:'center',split:false" style="background:#eee;padding:10px 20px 10px 20px">
            <div style="padding-left:10px;margin-bottom:10px"><h5 style="margin:0">门户信息</h5></div>
            <div style="border:1px solid lightgrey;padding-left:10px">
                <p>
                    <span style="width:60px;text-align:justify;display:inline-block">
                        法人代表:
                    </span>
                    <input class="easyui-textbox" type="text" name="bossName" style="width:150px;"
                           data-options="required:true,missingMessage:'必填'" />
                    <span id="bossNameError" error style="width:150px;color:red;display:inline-block"></span>
                    <span style="margin-left:50px;width:60px;text-align:justify;display:inline-block">
                        注册日期:
                    </span>
                    <input type="text" class="easyui-datetimebox" id="regDatetime" required="required" style="width:150px;" />
                </p>
                <p style="margin-top:20px">
                    <span style="width:60px;text-align:justify;display:inline-block">
                        证件类型:
                    </span>
                    <input name="cardType" value="--请选择--" style="width:150px" />
                    <span style="width:150px;color:red;display:inline-block"></span>
                    <span style="margin-left:50px;width:60px;text-align:justify;display:inline-block">
                        证件号码:
                    </span>
                    <input class="easyui-textbox" type="text" name="cardNum" style="width:150px;"
                           data-options="required:true,missingMessage:'必填'" />
                    <span id="cardNumError" error style="width:150px;color:red;display:inline-block"></span>
                    <input type="hidden" name="cardTypeName" value="" />
                </p>
                <p style="margin-top:20px">
                    <span style="width:60px;text-align:justify;display:inline-block">
                        公司电话:
                    </span>
                    <input class="easyui-textbox" type="text" name="companyTel" style="width:150px;" />
                    <span id="companyTelError" error style="width:150px;color:red;display:inline-block"></span>
                    <span style="margin-left:50px;width:60px;text-align:justify;display:inline-block">
                        公司传真:
                    </span>
                    <input class="easyui-textbox" type="text" name="companyFax" style="width:150px;"
                           data-options="required:true,missingMessage:'必填'" />
                    <span style="width:150px;color:red;display:inline-block"></span>
                </p>
                <p style="margin-top:20px">
                    <span style="width:60px;text-align:justify;display:inline-block">
                        国家:
                    </span>
                    <input class="easyui-textbox" type="text" name="country" style="width:150px;" />
                    <span id="countryError" error style="width:150px;color:red;display:inline-block"></span>
                    <span style="margin-left:50px;width:60px;text-align:justify;display:inline-block">
                        公司地址:
                    </span>
                    <input class="easyui-textbox" type="text" name="companyAddress" style="width:150px;"
                           data-options="required:true,missingMessage:'必填'" />
                    <span id="companyAddressError" error style="width:150px;color:red;display:inline-block"></span>
                </p>
                <p style="margin-top:20px">
                    <span>
                        省/地区:
                    </span>
                    <input name="province"  value="--请选择--" style="width:150px" />
                    <span style="margin-left:45px;">
                        城市:
                    </span>
                    <input name="city"  value="--请选择--" style="width:150px" />
                    <span style="margin-left:45px;">
                        区:
                    </span>
                    <input name="area"  value="--请选择--" style="width:150px" />
                </p>
                <p>
                    <span style="display:block">备注</span>
                    <textarea name="memo" rows="5" cols="100"></textarea>
                </p>
            </div>
        </div>
    </form>

    <script>

        $(
            function ()
            {
                //页面加载设置企业类型选项
                $("[name=customType]").combobox(
                    {
                        url:'${ctx}/do/comboboxJsonStr',
                        queryParams:{"action":"customType"},
                        valueField:'configTypeValue',
                        textField:'configValue',
                        editable: false,
                        onSelect: function( rec )
                        {
                            $("[name=customTypeName]").val( rec.configValue );
                        }
                    });
                //页面加载设置证件类型选项
                $("[name=cardType]").combobox(
                    {
                        url:'${ctx}/do/comboboxJsonStr',
                        queryParams:{"action":"cardType"},
                        valueField:'configTypeValue',
                        textField:'configValue',
                        editable: false,
                        onSelect: function( rec )
                        {
                            $("[name=cardTypeName]").val( rec.configValue );
                        }
                    });

                //设置地区选项combobox
                var areaCombobox = $("[name=area]").combobox(
                                {
                                    disable:true,
                                    valueField:'areaId',
                                    textField:'area',
                                    editable: false
                                });

                //设置城市选项combobox
                var cityCombobox = $("[name=city]").combobox(
                                {
                                    disable:true,
                                    method:"GET",
                                    valueField:'cityId',
                                    textField:'city',
                                    editable: false,
                                    //选择城市时级联地区
                                    onSelect: function( city )
                                    {
                                        areaCombobox.combobox(
                                            {
                                                disable:false,
                                                url:'${ctx}/do/comboboxJsonStr',
                                                queryParams:{"action":"area","cityId":city.cityId},
                                                valueField:'areaId',
                                                textField:'area',
                                                editable: false
                                            }).combobox('clear');

                                    }
                                });

                //设置省份选择combobox
                $("[name=province]").combobox(
                    {
                        url:'${ctx}/do/comboboxJsonStr',
                        queryParams:{"action":"province"},
                        valueField:'provinceId',
                        textField:'province',
                        editable: false,
                        //选择省份时级联城市
                        onSelect: function( province )
                        {
                            cityCombobox.combobox(
                                {
                                    disable:false,
                                    url:'${ctx}/do/comboboxJsonStr',
                                    queryParams:{"action":"city","provinceId":province.provinceId},
                                    valueField:'cityId',
                                    textField:'city',
                                    editable: false
                                    //选择城市时级联地区
                                }).combobox('clear');
                        }
                    });
            }
        );

        //点击保存按钮提交表单
        function submitForm()
        {
            var dateTime = $("#regDatetime").datetimebox('getValue');
            //设置表单请求
            $("#add").form( 'submit' ,
                {
                    url:"${ctx}/do/addCustom",
                    //提交前设置表单携带参数
                    onSubmit: function(param){
                        param.dateTime = dateTime;
                    },
                    //提交成功后处理返回值
                    success:function(data)
                    {
                        //注意需要将返回值转换为json
                        var json = JSON.parse(data);
                        //若输入信息格式不匹配,验证错误
                        if( json.errorMessage )
                        {
                            var errorMessage = json.errorMessage;
                            //回显验证错误消息提示
                            //var customNameError = json.errorMessage.customName;
                            //$("#customNameError").text( customNameError );
                            //打印验证错误消息提示
                            for( var i in errorMessage )
                            {
                                var spanId = i + "Error";
                                $( "#" + spanId ).text( errorMessage[i] );
                            }
                        }
                        else
                        {
                            //清空验证错误
                            clearError();
                            if( json.message == 1 )
                            {
                                $.messager.alert('添加操作','添加成功','info',
                                    function(result)
                                    {
                                        window.location.href = "${ctx}/do/toAgentCustomManagePage";
                                    });
                            }
                            else
                            {
                                $.messager.alert('添加操作','添加失败','info',
                                    function()
                                    {
                                        window.location.href = "${ctx}/do/toAgentCustomManagePage";
                                    });
                            }
                        }
                    }
                });
        }

        //清空错误消息提示框
        function clearError()
        {
            //var len = $("[error]").length;
            $("[error]").text("");
        }

        //点击取消按钮返回客户管理页面
        function cancel()
        {
            window.location.href = "${ctx}/do/toAgentCustomManagePage";
        }

    </script>
</body>
</html>
